<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>汽车入库</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<!-- 查询条件开始-->
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" method="post" id="searchFrm">
            <div class="layui-form-item">
                <div class="layui-inline" style="width: 400px;">
                    <label class="layui-form-label">出租单号:</label>
                    <div class="layui-input-block">
                        <input type="text" name="rentid" id="search_rentId"  autocomplete="off" class="layui-input" placeholder="请输入出租单号"
                               lay-verify="required" lay-reqText="请输入出租单号">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block" >
                        <button type="button" class="layui-btn layui-icon layui-icon-search" lay-submit lay-filter="doSearch">查询</button>
                        <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
                    </div>
                </div>
            </div>


        </form>
    </blockquote>
</form>
<!-- 查询条件结束-->

<div id="content" >
    <!-- 检查单位的表单 -->
    <blockquote class="layui-elem-quote" style="margin-top: 10px;">
        <h2>检查单表单</h2>
        <hr>
        <form class="layui-form" method="post" id="checkFrm" lay-filter="checkFrm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <!-- 隐藏域 -->
                    <input type="hidden" name="carId" id="carId">
                    <label class="layui-form-label">检查单号:</label>
                    <div class="layui-input-inline" style="width: 250px">
                        <input type="text" name="checkid" readonly="readonly"
                               placeholder="请输入检查单号" id="checkid" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出租单号:</label>
                    <div class="layui-input-inline" style="width: 250px">
                        <input type="text" name="rentid" readonly="readonly"
                               placeholder="请输入出租单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">检查时间:</label>
                    <div class="layui-input-inline" style="width: 250px">
                        <input type="text" name="checkdate" readonly="readonly"
                               placeholder="请选择检查时间" id="checkdate" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">赔付金额:</label>
                    <div class="layui-input-inline" style="width: 250px">
                        <input type="text" name="paymoney" placeholder="请输入赔付金额"
                               lay-verify="required|number" value="0" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">操作员:</label>
                    <div class="layui-input-inline" style="width: 250px">
                        <input type="text" name="opername" placeholder="请输入操作员"
                               readonly="readonly" autocomplete="off" class="layui-input">
                    </div>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">存在问题:</label>
                <div class="layui-input-block">
                    <input type="text" name="problem" lay-verify="required" placeholder="请输入出存在问题"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">问题描述:</label>
                <div class="layui-input-block">
						<textarea placeholder="请输入问题描述" lay-verify="required" name="checkdesc"
                                  class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item" style="text-align: center;">
                <button type="button" lay-submit lay-filter="doSubmit"
                        class="layui-btn layui-btn-normal  layui-icon layui-icon-ok"
                        id="doSubmit">保存</button>
            </div>
        </form>
    </blockquote>

    <!-- 出租单  车辆  客户的信息展开 -->
    <div style="padding: 10px; background-color: #F2F2F2;">
        <div class="layui-row layui-col-space8">
            <div class="layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-header">车辆信息</div>
                    <div class="layui-card-body" id="car_carnumber">
                    </div>
                    <div class="layui-card-body" id="car_cartype">
                    </div>
                    <div class="layui-card-body" id="car_color">
                    </div>
                    <div class="layui-card-body" id="car_price">
                    </div>
                    <div class="layui-card-body" id="car_rentprice">
                    </div>
                    <div class="layui-card-body" id="car_deposit">
                    </div>
                    <div class="layui-card-body" id="car_description">
                    </div>
                    <div class="layui-card-body">
                        车辆图片:<img alt="" width="200" height="150" id="car_carimg" src="">
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-header">出租单信息</div>
                    <div class="layui-card-body" id="rent_rentid">
                    </div>
                    <div class="layui-card-body" id="rent_price">
                    </div>
                    <div class="layui-card-body" id="rent_begindate">
                    </div>
                    <div class="layui-card-body" id="rent_returndate">
                    </div>
                    <div class="layui-card-body" id="rent_opername">
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-header">客户信息</div>
                    <div class="layui-card-body" id="customer_identity">
                    </div>
                    <div class="layui-card-body" id="customer_custname">
                    </div>
                    <div class="layui-card-body" id="customer_sex">
                    </div>
                    <div class="layui-card-body" id="customer_address">
                    </div>
                    <div class="layui-card-body" id="customer_phone">
                    </div>
                    <div class="layui-card-body" id="customer_career">
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer','laydate'],function () {
        var $=layui.jquery;
        var form=layui.form;
        var table=layui.table;
        var layer=layui.layer;
        var laydate=layui.laydate;

        //监听表单提交事件
        form.on("submit(doSearch)",function (data) {
            //根据输入的出租单号查询出租单是否存在
            $.get("/bus/rent/checkRentByRentId",data.field,function(result){
                //判断单号是否存在
                if(result.exist){
                    //判断当前出租单的状态
                    //如果出租单已归还，则提示
                    if(result.rent.rentflag==1){
                        layer.msg("您输入的出租单相关车辆已经归还，无需再入库");
                        initCheckFormDataByFalg(data.field.rentid);
                    }else {
                        //如果是未归还，生成检查单信息
                        //调用初始化检查数据的方法
                        initCheckFormData(data.field.rentid);
                    }

                }else{
                    //不存在时提示信息
                    layer.msg(result.message);
                    resetValue();
                }
            },"json");
            return false;
        });

        /**
         * 初始化检查单
         */
            function initCheckFormData(rentid) {
                $.get("/bus/check/initCheckFormData", {"rentid":rentid}, function (obj) {
                    //检查单
                    var check=obj.check;
                    form.val("checkFrm",check);
                    //客户
                    var customer=obj.customer;
                    $("#customer_identity").html("身份证号: "+customer.identity);
                    $("#customer_custname").html("客户姓名: "+customer.custname);
                    $("#customer_sex").html("客户性别: "+(customer.sex==1?'男':'女'));
                    $("#customer_address").html("客户地址: "+customer.address);
                    $("#customer_phone").html("客户电话: "+customer.phone);
                    $("#customer_career").html("客户职位: "+customer.career);

                    //出租单
                    var rent=obj.rent;

                    $("#rent_rentid").html("出租单号: "+rent.rentid);
                    $("#rent_price").html("出租价格: "+rent.price);
                    $("#rent_begindate").html("起租时间: "+rent.begindate);
                    $("#rent_returndate").html("还车时间: "+rent.returndate);
                    $("#rent_opername").html("操作员: "+rent.opername);

                    //车辆信息
                    var car=obj.car;
                    $("#car_carnumber").html("车辆号牌: "+car.carnumber);
                    $("#car_cartype").html("车辆类型: "+car.cartype);
                    $("#car_color").html("车辆颜色: "+car.color);
                    $("#car_price").html("购买价格: "+car.price);
                    $("#car_rentprice").html("出租价格: "+car.rentprice);
                    $("#car_deposit").html("出租押金: "+car.deposit);
                    $("#car_description").html("车辆描述: "+car.description);
                    $("#car_carimg").attr("src","/file/showImages/"+car.carimg);
                    $("#carId").val(car.id);//隐藏域赋值，用于修改车辆信息

                }, "json");
            }


        /**
         * 初始化检查单数据
         */
        function resetValue() {
            //清空检查单表单
            $("#checkFrm")[0].reset();
            $("#customer_identity").html("");
            $("#customer_custname").html("");
            $("#customer_sex").html("");
            $("#customer_address").html("");
            $("#customer_phone").html("");
            $("#customer_career").html("");

            //出租单


            $("#rent_rentid").html("");
            $("#rent_price").html("");
            $("#rent_begindate").html("");
            $("#rent_returndate").html("");
            $("#rent_opername").html("");

            //车辆信息

            $("#car_carnumber").html("");
            $("#car_cartype").html("");
            $("#car_color").html("");
            $("#car_price").html("");
            $("#car_rentprice").html("");
            $("#car_deposit").html("");
            $("#car_description").html("");
            $("#car_carimg").removeAttr("src")
            $("#carId").val("");//隐藏域赋值，用于修改车辆信息

            }

            //监听表单提交事件
            form.on("submit(doSubmit)",function (data) {
                //序列化
                var params=$("#checkFrm").serialize();

                $.post("/bus/check/addCheck", params, function (result) {
                    layer.msg(result.message);
                    //清空表单数据
                    $("#checkFrm")[0].reset();
                }, "json");

                return false;
            })

    });

    /**
     * 已归还的汽车显示信息
     * @param rentid
     */
    function initCheckFormDataByFalg(rentid) {
        $.get("/bus/check/initCheckFormData", {"rentid":rentid}, function (obj) {

            //客户
            var customer=obj.customer;
            $("#customer_identity").html("身份证号: "+customer.identity);
            $("#customer_custname").html("客户姓名: "+customer.custname);
            $("#customer_sex").html("客户性别: "+(customer.sex==1?'男':'女'));
            $("#customer_address").html("客户地址: "+customer.address);
            $("#customer_phone").html("客户电话: "+customer.phone);
            $("#customer_career").html("客户职位: "+customer.career);

            //出租单
            var rent=obj.rent;

            $("#rent_rentid").html("出租单号: "+rent.rentid);
            $("#rent_price").html("出租价格: "+rent.price);
            $("#rent_begindate").html("起租时间: "+rent.begindate);
            $("#rent_returndate").html("还车时间: "+rent.returndate);
            $("#rent_opername").html("操作员: "+rent.opername);

            //车辆信息
            var car=obj.car;
            $("#car_carnumber").html("车辆号牌: "+car.carnumber);
            $("#car_cartype").html("车辆类型: "+car.cartype);
            $("#car_color").html("车辆颜色: "+car.color);
            $("#car_price").html("购买价格: "+car.price);
            $("#car_rentprice").html("出租价格: "+car.rentprice);
            $("#car_deposit").html("出租押金: "+car.deposit);
            $("#car_description").html("车辆描述: "+car.description);
            $("#car_carimg").attr("src","/file/showImages/"+car.carimg);
            $("#carId").val(car.id);//隐藏域赋值，用于修改车辆信息

        }, "json");
    }
    
    
</script>
</body>
</html>